home *** CD-ROM | disk | FTP | other *** search
- Path: wmwap1.math.uni-wuppertal.de!usenet
- From: Oliver Heinz <heinz@lfa.uni-wuppertal.de>
- Newsgroups: comp.lang.c++
- Subject: Newbie exception question
- Date: Tue, 05 Mar 1996 15:02:25 +0100
- Organization: University of Wuppertal, Germany
- Message-ID: <313C4971.6956@lfa.uni-wuppertal.de>
- NNTP-Posting-Host: welfag.elektro.uni-wuppertal.de
- Mime-Version: 1.0
- Content-Type: multipart/mixed; boundary="------------1372500F2847"
- X-Mailer: Mozilla 2.0 (X11; I; IRIX 5.3 IP20)
- CC: heinz@lfa.uni-wuppertal.de
-
- This is a multi-part message in MIME format.
-
- --------------1372500F2847
- Content-Type: text/plain; charset=iso-8859-2
- Content-Transfer-Encoding: 7bit
-
- Hello out there ...
-
- I'm new to exception handling with C++, and so I've tried out a simple
- program. It reads one argument from the command line and compares, if
- it is a '5'. The program raises the exception, but the catch statement
- doesn't work.
-
- Any help is greatly appreciated, thanks in advance
-
- Oliver
-
-
-
- The code:
-
- #include <stdlib.h>
-
- #include <iostream.h>
-
- int
- main(int argc, char *const *argv)
- {
- long int _myint;
-
- try {
- cout << "The first command line option was: " << argv[1] << endl;
- _myint=strtol(argv[1], NULL, 10);
- if (_myint==5) {
- cout << "Succesfull comparison, raising exception." << endl;
- throw (_myint);
- }
- }
- catch (long int i) {
- cout << "An exception occurred: " << i << endl;
- }
-
- cout << "Normal program exit ..." << endl;
- return 0;
- }
-
-
-
- Compiled with gcc version 2.7.2:
-
- gcc -o tmp -fhandle-exceptions tmp.C -lstdc++
-
- (No warnings, no errors)
-
-
-
- The output:
-
- > tmp 5
- The first command line option was: 5
- Succesfull comparison, raising exception.
- Normal program exit ...
-
- (Oops, where is the cout from the catch statement ?)
-
- --------------1372500F2847
- Content-Type: text/plain; charset=iso-8859-2
- Content-Transfer-Encoding: 7bit
- Content-Disposition: inline; filename="absender"
-
- ============================================================================
- Oliver Heinz | E-mail:
- University of Wuppertal | heinz@lfa.uni-wuppertal.de
- Department of Electrical Engineering |
- Fuhlrottstr. 10 |
- D-42110 Wuppertal, GERMANY |
- ============================================================================
-
- --------------1372500F2847--
-
-